package com.ssl.basics.sort;

/**
 * 描述：冒泡排序
 *
 * @author ssl
 * @create 2021/02/19 16:08
 */
public class Bubble {

    public static void main(String[] args) {
        int[] arr = {8, 9, 4, 6, 52, 68, 12, 80, 38, 37, 50};
        sort(arr);
        for (int a : arr) {
            System.out.println(a);
        }
    }

    public static int[] sort(int[] arr) {
        for (int i = 0; i < arr.length - 1; i++) {
            for (int j = 0; j < arr.length - i - 1; j++) {
                int x = arr[j];
                int y = arr[j + 1];
                if (x > y) {
                    int temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                }
            }
        }
        return arr;
    }
}
